<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="resource/js/layuimini-v2/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="resource/js/layuimini-v2/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-normal layui-btn-sm data-run-btn" lay-event="search">
                运行
            </button>
        </div>
        <div id="editor" style="height: 200px; width: 100%"></div>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    </div>
</div>
<!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
<script src="resource/js/layuimini-v2/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="resource/js/layuimini-v2/js/lay-config.js?v=2.0.0" charset="utf-8"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.32.7/ace.js"></script><script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;


        var linkId = '{{.LinkId}}'
        var dbName = '{{.DbName}}'
        console.info("tableExec");
        var editor = ace.edit("editor");

        theme = "xcode"
        language = "sql"
        editor.setTheme("ace/theme/" + theme);
        editor.session.setMode("ace/mode/" + language);
        //自动换行,设置为off关闭
        editor.setOption("wrap", "free")

        //启用提示菜单
        ace.require("ace/ext/language_tools");
        editor.setOptions({
            enableBasicAutocompletion: true,
            enableSnippets: true,
            enableLiveAutocompletion: true
        });


        $(".data-run-btn").on("click",function (){

            let sql = editor.getValue();
            var data = {
                linkId:linkId,
                dbName:dbName,
                sql:sql
            }

            $.ajax({
                url:"/td/table/execSql/post",
                type:"POST",
                data:data,
                dataType : 'json',
                async:false,
                success:function (res) {
                    console.info(res)
                    if(res.code == 0 && res.data.result){
                        layer.msg("执行成功")
                    }
                },
                error:function(){

                }
            });

        });


    });
</script>

</body>
</html>